home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / datamgr / faddindx.frm < prev    next >
Text File  |  1995-10-23  |  8KB  |  286 lines

  1. VERSION 2.00
  2. Begin Form fAddIndex 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Add Index"
  6.    ClientHeight    =   3930
  7.    ClientLeft      =   1095
  8.    ClientTop       =   1485
  9.    ClientWidth     =   7350
  10.    Height          =   4335
  11.    Left            =   1035
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   3930
  16.    ScaleWidth      =   7350
  17.    Top             =   1140
  18.    Visible         =   0   'False
  19.    Width           =   7470
  20.    Begin CommandButton cCancel 
  21.       Cancel          =   -1  'True
  22.       Caption         =   "Cancel"
  23.       Height          =   375
  24.       Left            =   6000
  25.       TabIndex        =   10
  26.       Top             =   720
  27.       Width           =   1095
  28.    End
  29.    Begin CommandButton cDone 
  30.       Caption         =   "&Done"
  31.       Height          =   375
  32.       Left            =   6000
  33.       TabIndex        =   9
  34.       Top             =   240
  35.       Width           =   1095
  36.    End
  37.    Begin CommandButton cRemove 
  38.       Caption         =   "&Remove"
  39.       Enabled         =   0   'False
  40.       Height          =   375
  41.       Left            =   2520
  42.       TabIndex        =   4
  43.       Top             =   2400
  44.       Width           =   1095
  45.    End
  46.    Begin CommandButton cAdd 
  47.       Caption         =   "Add (D&ec)"
  48.       Enabled         =   0   'False
  49.       Height          =   375
  50.       Index           =   1
  51.       Left            =   2520
  52.       TabIndex        =   3
  53.       Top             =   1920
  54.       Width           =   1095
  55.    End
  56.    Begin CommandButton cAdd 
  57.       Caption         =   "&Add (Asc)"
  58.       Enabled         =   0   'False
  59.       Height          =   375
  60.       Index           =   0
  61.       Left            =   2520
  62.       TabIndex        =   2
  63.       Top             =   1440
  64.       Width           =   1095
  65.    End
  66.    Begin TextBox cIndexName 
  67.       Height          =   285
  68.       Left            =   360
  69.       TabIndex        =   0
  70.       Top             =   360
  71.       Width           =   2055
  72.    End
  73.    Begin CheckBox cPrimary 
  74.       BackColor       =   &H00C0C0C0&
  75.       Caption         =   "&Primary Index"
  76.       Height          =   255
  77.       Left            =   3840
  78.       TabIndex        =   8
  79.       Top             =   3600
  80.       Width           =   1695
  81.    End
  82.    Begin CheckBox cUnique 
  83.       BackColor       =   &H00C0C0C0&
  84.       Caption         =   "Require &Unique Index Values"
  85.       Height          =   255
  86.       Left            =   480
  87.       TabIndex        =   7
  88.       Top             =   3600
  89.       Width           =   2895
  90.    End
  91.    Begin ListBox cFields 
  92.       Height          =   2370
  93.       Left            =   3720
  94.       TabIndex        =   6
  95.       Top             =   960
  96.       Width           =   2040
  97.    End
  98.    Begin ListBox cFieldList 
  99.       Height          =   2370
  100.       Left            =   360
  101.       Sorted          =   -1  'True
  102.       TabIndex        =   1
  103.       Top             =   975
  104.       Width           =   2040
  105.    End
  106.    Begin Label cTableName 
  107.       Caption         =   "cTableName"
  108.       Height          =   255
  109.       Left            =   4320
  110.       TabIndex        =   5
  111.       Top             =   3960
  112.       Visible         =   0   'False
  113.       Width           =   2535
  114.    End
  115.    Begin Label Label3 
  116.       BackColor       =   &H00C0C0C0&
  117.       Caption         =   "&Index Name:"
  118.       Height          =   255
  119.       Left            =   360
  120.       TabIndex        =   13
  121.       Top             =   120
  122.       Width           =   2055
  123.    End
  124.    Begin Label Label2 
  125.       BackColor       =   &H00C0C0C0&
  126.       Caption         =   "Field&s in Index"
  127.       Height          =   255
  128.       Left            =   3720
  129.       TabIndex        =   12
  130.       Top             =   720
  131.       Width           =   1815
  132.    End
  133.    Begin Label Label1 
  134.       BackColor       =   &H00C0C0C0&
  135.       Caption         =   "&Fields in Table"
  136.       Height          =   255
  137.       Left            =   360
  138.       TabIndex        =   11
  139.       Top             =   720
  140.       Width           =   1935
  141.    End
  142. End
  143. Sub cAdd_Click (Index As Integer)
  144.     Dim PlMn As String
  145.  
  146.     PlMn = "+"
  147.     If Index = 1 Then PlMn = "-"
  148.  
  149.     cFields.AddItem PlMn & cFieldList.List(cFieldList.ListIndex)
  150.     cFieldList.RemoveItem cFieldList.ListIndex
  151.  
  152.     cFieldList.ListIndex = -1
  153.     For I = 0 To 1
  154.         cAdd(I).Enabled = False
  155.     Next I
  156.     If cFields.ListCount > 0 And cIndexName <> "" Then
  157.         cDone.Enabled = True
  158.         cDone.Default = True
  159.     End If
  160.     cFieldList.SetFocus
  161. End Sub
  162.  
  163. Sub cCancel_Click ()
  164. 'Close Dialog
  165. Unload fAddIndex
  166. End Sub
  167.  
  168. Sub cDone_Click ()
  169.     Dim idx As New Index
  170.     Dim tempFields As String
  171.     Dim temp As String
  172.     Dim I As Integer
  173.     Dim AddErr As Integer
  174.     
  175.     On Error Resume Next
  176.  
  177.     'Set up index properties
  178.     idx.Name = cIndexName
  179.     idx.Primary = -cPrimary
  180.     idx.Unique = -cUnique
  181.     tempFields = ""
  182.     For I = 0 To cFields.ListCount - 1
  183.         temp = cFields.List(I)
  184.         temp = Left$(temp, 1) & "[" & Right$(temp, Len(temp) - 1) & "]"
  185.         tempFields = tempFields + temp + ";"
  186.     Next I
  187.     If Len(tempFields) > 255 Then
  188.         MsgBox "Too many fields in Index.  Remove some and try again.", 64, "Data Manager"
  189.     Else
  190.         'Remove the last semicolon
  191.         idx.Fields = Left$(tempFields, Len(tempFields) - 1)
  192.         
  193.         'Append to the Index Collection
  194.         gDatabase.TableDefs(cTableName).Indexes.Append idx
  195.         AddErr = Err
  196.         If AddErr <> 0 Then
  197.             MsgBox "Error Adding Index: " + Chr$(13) + Error$, 64, "Data Manager"
  198.         End If
  199.     
  200.         If AddErr = 3283 Then 'Primary Key already exists
  201.             'cPrimary = 0
  202.         ElseIf AddErr = 3277 Then 'Too many fields in list
  203.             cFields.ListIndex = 0
  204.         Else
  205.             'Close Dialog
  206.             Unload fAddIndex
  207.         End If
  208.     End If
  209. End Sub
  210.  
  211. Sub cFieldList_Click ()
  212.     If cFieldList.ListIndex <> -1 Then
  213.         cAdd(0).Enabled = True
  214.         cAdd(1).Enabled = True
  215.         cRemove.Enabled = False
  216.         cFields.ListIndex = -1
  217.         cAdd(0).Default = True
  218.     End If
  219. End Sub
  220.  
  221. Sub cFieldList_DblClick ()
  222.     'Add the item
  223.     cAdd_Click (0)
  224. End Sub
  225.  
  226. Sub cFields_Click ()
  227.     If cFields.ListIndex <> -1 Then
  228.         cFieldList.ListIndex = -1
  229.         cRemove.Enabled = True
  230.         cAdd(0).Enabled = False
  231.         cAdd(1).Enabled = False
  232.     End If
  233. End Sub
  234.  
  235. Sub cFields_DblClick ()
  236.     'Remove the item
  237.     cRemove_Click
  238. End Sub
  239.  
  240. Sub cIndexName_Change ()
  241.     If cFields.ListCount > 0 And cIndexName <> "" Then
  242.         cDone.Enabled = True
  243.         cDone.Default = True
  244.     Else
  245.         cDone.Enabled = False
  246.     End If
  247. End Sub
  248.  
  249. Sub cRemove_Click ()
  250.     Dim temp As String
  251.     temp = cFields.List(cFields.ListIndex)
  252.     cFields.RemoveItem cFields.ListIndex
  253.  
  254.     cFieldList.AddItem Right$(temp, Len(temp) - 1)
  255.  
  256.     If cFields.ListCount <= 0 Then
  257.         cDone.Enabled = False
  258.     End If
  259.     cFieldList.ListIndex = 0
  260.     cFieldList.SetFocus
  261. End Sub
  262.  
  263. Sub Form_Activate ()
  264.     Dim I As Integer
  265.     Dim TD As Tabledef
  266.     Dim FieldCount As Integer
  267.  
  268.     On Error Resume Next
  269.  
  270.     Screen.MousePointer = 11
  271.     Set TD = gDatabase.TableDefs(cTableName.Caption)
  272.     FieldCount = TD.Fields.Count
  273.     If FieldCount > 0 Then 'it should be
  274.         For I = 0 To FieldCount - 1
  275.             If TD.Fields(I).Type <= 10 Then  'not ole or memo
  276.                 cFieldList.AddItem TD.Fields(I).Name
  277.             End If
  278.         Next I
  279.     End If
  280.     Screen.MousePointer = 0
  281.     'enable buttons
  282.     cDone.Enabled = False
  283.  
  284. End Sub
  285.  
  286.